package com.water.controller;

import com.water.pojo.Team;
import com.water.vo.QueryVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @author wsj
 * @version 1.0
 * @description: TODO
 * @date 2022/1/17 22:18
 */
@Controller
@RequestMapping("/hello")
public class HelloController {

    @RequestMapping("/test")
    public ModelAndView test(Integer teamId, String teamName, String teamLocation){
        System.out.println("==========获取参数========");
        System.out.println("球队id："+teamId);
        System.out.println("球队name："+teamName);
        System.out.println("球队location："+teamLocation);
        System.out.println("==========OK==============");
        System.out.println("=========git=====");
        return new ModelAndView("index");
    }

    @RequestMapping("/test2")
    public ModelAndView test2(Team team){
        System.out.println("=========test2========");
        System.out.println(team);
        return new ModelAndView("ok");
    }

    @RequestMapping("/test3")
    public ModelAndView test3(@RequestParam(value = "id",required = false)Integer teamId,
                              @RequestParam(value = "name",required = true)String teamName,
                              @RequestParam("location") String teamLocation){
        System.out.println("==========获取参数test3========");
        System.out.println("球队id："+teamId);
        System.out.println("球队name："+teamName);
        System.out.println("球队location："+teamLocation);
        System.out.println("==========OK==============");
        System.out.println("=========git=====");
        return new ModelAndView("index");
    }

    @RequestMapping("test4")
    public ModelAndView test4(HttpServletRequest request){
        String id = request.getParameter("id");
        String name = request.getParameter("name");
        String location = request.getParameter("location");
        System.out.println(Integer.valueOf(id));//转换为数值
        System.out.println(name);
        System.out.println(location);
        return new ModelAndView("ok");
    }
    //http://localhost:8080/hello/test5/12/waterking
    @RequestMapping("/test5/{id}/{name}")
    public ModelAndView test5(@PathVariable("id")Integer teamId, @PathVariable("name")String teamName){
        System.out.println("=====test5======");
        System.out.println("id:"+teamId);
        System.out.println("name:"+teamName);
        return new ModelAndView("ok");
    }

    /**
     * 日期，需要注解，对象
     * @param team
     * @return
     */
    @RequestMapping("/test6")
    public ModelAndView test6(Team team){
        System.out.println("=========test6========");
        System.out.println(team);
        return new ModelAndView("ok");
    }

    /**
     * 数组
     * @param teamName
     * @param name
     * @return
     */
    @RequestMapping("/test7")
    public ModelAndView test7(String[] teamName, String[] name){
        System.out.println("=========test7========");
        for (String s : teamName) {
            System.out.println(s);
        }
        System.out.println("--------name------");
        for (String s : name) {
            System.out.println(s);
        }
        return new ModelAndView("ok");
    }

    @RequestMapping("/test8")
    public ModelAndView test8( QueryVo vo){
        System.out.println("=========test8========");
        for (Team team : vo.getTeamList()) {
            System.out.println(team);
        }
        return new ModelAndView("ok");
    }

}
